<template>
	<view class="m-b-25 p-25 bg-white radius-15">
		<view class="seckill-good-box">
			<view class="title-box">
				<view class="title-icon">
					<image class="icon" :src="handleStaticResources('/static/images/icon/icon-seckill.png')"></image>
					<text class="tit">{{ props.data.title }}</text>
				</view>
				<coreshop-view-more @hanldeClickViewMore="hanldeClickViewMore" />
			</view>
			<view class="card-box" v-for="item, index in props.data?.list?.slice(0, Number(props.data.limit))"
				:key="index">
				<coreshop-goods-card :goodsData="hanldeCombinationGoodsData(item)" @hanldeClickGoods="hanldeClickGoods">
					<template #goodPrice>
						<view class="time" v-if="item.startStatus == IsStartSeckillEnum.start && item.startStatus">
							<view class="time-tit">仅剩：</view><uv-count-down class="down-box"
								:time="item.timestamp * 1000" format="DD天HH时mm分ss秒"></uv-count-down>
						</view>
						<view class="time" v-if="item.startStatus == IsStartSeckillEnum.pending && item.startStatus">
							<view class="time-tit">即将开始：</view><uv-count-down class="down-box"
								:time="item.timestamp * 1000" format="DD天HH时mm分ss秒"></uv-count-down>
						</view>
						<view class="time" v-if="item.startStatus == IsStartSeckillEnum.end && item.startStatus">
							<view class="time-tit">已结束：</view><uv-count-down class="down-box"
								:time="item.timestamp * 1000" format="DD天HH时mm分ss秒"></uv-count-down>
						</view>
						<view class="price-msg">
							<view class="price-box">
								<view class="price">
									<text class="symbol">￥</text>
									<text class="num">{{ item.price }}</text>
								</view>
								<view class="underlin-price">￥{{ item.mktPrice }}</view>
							</view>
							<view class="btn btn-buy" v-if="item.startStatus == IsStartSeckillEnum.start"
								@click="hanldeClickGoods(item)">马上秒</view>
							<view class="btn btn-start" v-if="item.startStatus == IsStartSeckillEnum.pending">即将开始
							</view>
							<view class="btn btn-end" v-if="item.startStatus == IsStartSeckillEnum.end">已结束</view>
						</view>
					</template>
				</coreshop-goods-card>
			</view>
		</view>
	</view>
</template>
<script setup lang="ts">
	import { IsStartSeckillEnum } from '@/core/enum';
	import { handleStaticResources, handleRouteNavigateTo } from '@/core/utils';

	const props = withDefaults(defineProps<{
		data : any,
	}>(), {
		data: {},
	});

	// 组合商品数据传入组件
	const hanldeCombinationGoodsData = (item : any) => {
		return {
			id: item.id,
			image: item.goodThumbnail,
			name: item.name,
			brief: item.goodName,
			price: item.price,
			mktprice: item.mktPrice,
			startStatus: item.startStatus,
		}
	}

	const hanldeClickViewMore = () => {
		handleRouteNavigateTo('/pages/subpackage/activity/seckill/list/list');
	}

	const hanldeClickGoods = (data : any) => {
		if (data.startStatus == IsStartSeckillEnum.end) {
			return;
		}
		handleRouteNavigateTo(`/pages/subpackage/activity/seckill/detail/detail?id=${data?.id}`)
	}
</script>
<style lang="scss" scoped>
	@import './home-seckill.scss';
</style>